<template>
  <div class="app-container">
   

    <el-table v-loading="loading" :data="feeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="费用编号" align="center" prop="feeId" />
      <el-table-column label="申请编号" align="center" prop="requestId" />
      
      <el-table-column label="费用标准编号" align="center" prop="feestandardId" />
      <el-table-column label="车辆编号，关联车辆信息表" align="center" prop="carId" /v-if="false>
      <el-table-column label="车辆类型" align="center" prop="model" />
      <el-table-column label="费用产生日期" align="center" prop="usageDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.usageDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="使用天数" align="center" prop="daysUsed" />
      <el-table-column label="每日费用" align="center" prop="feePerDay" />
      <el-table-column label="总费用" align="center" prop="totalFee" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['lh:fee:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    
  </div>
</template>

<script>
import { listFee, getFee, delFee, addFee, updateFee } from "@/api/lh/fee";

export default {
  name: "Fee",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车辆费用管理（按天数计算）表格数据
      feeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        requestId: null,
        feestandardId: null,
        carId: null,
        usageDate: null,
        daysUsed: null,
        feePerDay: null,
        totalFee: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        requestId: [
          { required: true, message: "申请编号不能为空", trigger: "blur" }
        ],
        feestandardId: [
          { required: true, message: "费用标准编号不能为空", trigger: "blur" }
        ],
        carId: [
          { required: true, message: "车辆编号，关联车辆信息表不能为空", trigger: "blur" }
        ],
        usageDate: [
          { required: true, message: "费用产生日期不能为空", trigger: "blur" }
        ],
        daysUsed: [
          { required: true, message: "使用天数不能为空", trigger: "blur" }
        ],
        feePerDay: [
          { required: true, message: "每日费用不能为空", trigger: "blur" }
        ],
        totalFee: [
          { required: true, message: "总费用不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询车辆费用管理（按天数计算）列表 */
    getList() {
      this.loading = true;
      listFee(this.queryParams).then(response => {
        console.log(response); 
        this.feeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        feeId: null,
        requestId: null,
        feestandardId: null,
        carId: null,
        usageDate: null,
        daysUsed: null,
        feePerDay: null,
        totalFee: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.feeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车辆费用管理（按天数计算）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const feeId = row.feeId || this.ids
      getFee(feeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改车辆费用管理（按天数计算）";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.feeId != null) {
            updateFee(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFee(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const feeIds = row.feeId || this.ids;
      this.$modal.confirm('是否确认删除车辆费用管理（按天数计算）编号为"' + feeIds + '"的数据项？').then(function() {
        return delFee(feeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('lh/fee/export', {
        ...this.queryParams
      }, `fee_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
